package roguespace;

import jgame.JGObject;
import treeship.core.service.Nexus;
import treeship.core.ship.impl.TreeShip;

public class TEnemy extends JGObject {
	/**
	 * 
	 */
	private final TheGame3 engine;
	private Double hp;

	// double timer = 0;

	public TEnemy(TheGame3 theGame3, TreeShip ship) {

		super("enemy", true, 0, -8, 2, null, 0, 0, -2);
		this.engine = theGame3;
		setPos(this.engine.random(32, this.engine.pfWidth() - 40), -8);
		setSpeedAbs(this.engine.random(-1, 1), 1.0 + this.engine.level / 2.0);
		hp = ship.getProperties().get(
				Nexus.getRepository().getArchetypePropertyFor("hp"));
		if (ship.getArchetype().getName().equals("Drone")) {
			setGraphic("chopperl1");
		} else if (ship.getArchetype().getName().equals("Tank")) {
			setGraphic("tanku");
		} else {
			throw new UnsupportedOperationException();
		}
	}

	@Override
	public void move() {
		this.engine.timer += gamespeed;
	}

	@Override
	public void hit(JGObject o) {
		if (o.getName().startsWith("bullet")) {
			o.remove();
			hp = hp - 10;
			if (hp < 0) {
				remove();

				this.engine.score += 5;
			}
		} else {
			remove();
			o.remove();
			this.engine.score += 5;
		}

	}

}